package com.hxzy.controller;

import com.hxzy.pojo.Result;
import com.hxzy.pojo.StatusCode;
import com.hxzy.pojo.Brand;
import com.hxzy.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    @GetMapping("/findAllBrand")
    public Result findAllBrand() {
        List<Brand> allBrand = brandService.findAllBrand();
        return new Result(true, StatusCode.OK,"查询成功！",allBrand);
    }

    @RequestMapping("/addBrand")
    public Result addBrand(@RequestBody Brand brand){
        int i = brandService.addBrand(brand);
        if (i > 0){
            return new Result(true,StatusCode.OK,"插入成功！","受影响行数为" + i );
        }
        return new Result(false,StatusCode.ERROR,"插入失败",null);
    }

}
